Skip to main content

All Questions

2votes
3answers
1kviews

Should classes with business logic inherit from a class with helper methods, or vise-versa?

I have a codebase where some classes contain both "essential" business logic, and "incidental" complexity. I am considering a refactor where I leverage inheritance to improve the ...
MYK's user avatar
  • 343
2votes
1answer
288views

Selective method inheritance

I have a lot of classes that are just a CRUD interface for microservices. They only have a param for the endpoint and some of the methods get_list / get_item / create / update / delete / activate / ...
xpy's user avatar
  • 129
2votes
1answer
170views

Late inheritance, enforce subclass behavior in the future

A super class Transaction has two subclasses TransactionA and TransactionB. A Transaction is composed of multiple events that occur in time for a specific key (a file, a person, etc.). Depending on ...
Pobe's user avatar
  • 153
0votes
2answers
1kviews

Should parent classes define methods using attributes of child classes?

I need to extend the parent classes of two child classes by adding shared methods to them. Starting with the initial definitions of the child classes: class ChildA(ParentA): pass class ChildB(...
pstatix's user avatar
  • 1,047
0votes
1answer
84views

Classes for integrating both BitBucket and GitHub into our site (an inheritance and composition question)

I am writing a system of callbacks for BitBucket and GitHub which should modify our site on certain events in BitBucket or GitHub. It is reasonable to make a base class like GitIntegration to handle ...
porton's user avatar
54votes
5answers
40kviews

Are Python mixins an anti-pattern?

I'm fully aware that pylint and other static analysis tools are not all-knowing, and sometimes their advice must be disobeyed. (This applies for various classes of messages, not just conventions.) If ...
cat's user avatar
  • 734
9votes
2answers
911views

Is Python's inheritance an "is-a" style of inheritance or a compositional style?

Given that Python allows for multiple inheritance, what does idiomatic inheritance in Python look like? In languages with single inheritance, like Java, inheritance would be used when you could say ...
Iain's user avatar
  • 450
2votes
2answers
755views

Python OO problem

I started learning Python yesterday and I ran into a problem. I like to hear some thoughts on it. As an exercise, I decided to build a chatserver. As part of the exercise, I wanted to write some ...
Erik Ros's user avatar
3votes
2answers
2kviews

One boilerplate class or many similar classes?

Lets say I'm trying to model a variety of objects that are virtually identical, the only difference being their class variables. Am I better off creating one boilerplate class and just calling the ...
Dan Oberlam's user avatar
1vote
2answers
264views

Python -- when should a class have-a rather than be-a?

This is related to "Extends is evil" vs. OCP? but separate because the idea of "implement the interface" doesn't exist in Python. I'm writing a class to pull some data off a webpage. It's ...
Patrick Collins's user avatar

close